<!DOCTYPE HTML>
<%@page import="shop.vo.UserBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="shop.vo.MessageBean"%>
<%@page import="java.util.List"%>
<%@page import="shop.factory.DAOFactory"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<meta charset="UTF-8" />
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<title>查看留言</title>
<style type="text/css">
	th,td{
		text-align: center;
	}
	a {
	text-decoration: none;
	color: #00CCFF;
	}
	
	a:hover {
		color: red;
	}
</style>
</head>
<%
	if (!(boolean)session.getAttribute("adminLogin")) {
		String path = request.getContextPath() + "/Admin/login.jsp";
		response.sendRedirect(path);
	}
%>
<body>
	<div class="container-fluid">
		<h3>反馈留言</h3>
		<div class="page-header" style="margin-top:10px ;"></div>
		<form action="<%=request.getContextPath() %>/MessageServlet" method="post">
		<input type="hidden" name="action" value="delete">
		<table class="table table-bordered table-condensed table-striped">
			<thead>
				<tr>
					<th>多选</th>
					<th>序号</th>
					<th>反馈人</th>
					<th>反馈信息</th>
					<th>反馈时间</th>
				</tr>
			</thead>
			<tbody>
			<%
					int nowPage = 1;
					int pageSize = 10;
					String str = request.getParameter("to");
					if (str != null) {
						nowPage = Integer.parseInt(str);
					}
					int up = nowPage;
					int next = nowPage;
					int maxPage = 0;
					int count = DAOFactory.getIMessageDAOInstance().getCount();
					if (count % pageSize == 0) {
						maxPage = count / pageSize;
					} else {
						maxPage = (count / pageSize) + 1;
					}
					if (next < maxPage) {
						next += 1;
					}
					if (up > 1) {
						up -= 1;
					}
					List<MessageBean> list = DAOFactory.getIMessageDAOInstance().list(
							nowPage, pageSize);
					Iterator<MessageBean> it = list.iterator();
					while (it.hasNext()) {
						MessageBean message = it.next();
						UserBean user = message.getUser();
				%>
				
				<tr class="danger">
					<td><input type="checkbox" value="<%=message.getUser_id() %>"
						id="cheboxId" name="cheboxId"></td>
					<td><%=message.getUser_id() %></td>
					<td><%=user.getUser_name() %></td>
					<td><%=message.getMessage() %></td>
					<td><%=message.getMessage_time() %></td>
				</tr>
				<%
					}
				%>
				<tr>
					<td colspan="12"><input type="button"
						value="全选" onclick="quan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="button" value="反选" onclick="fan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="reset" value="重置">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="submit" value="删除" onclick="return confirm('是否删除？')"></td>
				</tr>
				
				<tr>
					<td colspan="12"><span class="style1"> <a
							href="messageList.jsp?to=1">首页</a>&nbsp;|&nbsp; <a
							href="messageList.jsp?to=<%=up%>">上一页</a>&nbsp;|&nbsp;<a
							href="messageList.jsp?to=<%=next%>">下一页</a>&nbsp;|&nbsp; <a
							href="messageList.jsp?to=<%=maxPage%>">尾页</a>
					</span> &nbsp;&nbsp;第&nbsp;<%=nowPage%>&nbsp;页/共&nbsp;<%=maxPage%>&nbsp;页
					</td>
				</tr>
			</tbody>
		</table>
		</form>
	</div>
	<script type="text/javascript">
	function quan() {
		var checkObj = document.all("cheboxId");
		for (var i = 0; i < checkObj.length; i++) {
			checkObj[i].checked = true;
		}
	}
	function fan() {
		var checkObj = document.all("cheboxId");
		for (var i = 0; i < checkObj.length; i++) {
			if (checkObj[i].checked == true)
				checkObj[i].checked = false;
			else
				checkObj[i].checked = true;
		}
	}
</script>
</body>
</html>